#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include <cstring>
#include <sstream>
#include "detail/bmock_in_out_str_arg_val.hpp"
#include "bmock_in_out_raw_mem.hpp"
#include "detail/bmock_test_control_tools.hpp"
#include "bmock_util.hpp"

namespace bmock {
	static const control_tools_ptr          tl(new test_control_tools());
	static const char                       name[]   = "arg";
	static const unsigned char              s_val1[] = {0x81,0x82,0x87,00};
	static const unsigned char              s_val2[] = {0x85,0x82,0x86,00};
	static const size_t                     LEN      = sizeof(s_val1);
	static 	const arg_val_str expected((const char *)s_val1,(const char *)s_val2);

	BOOST_AUTO_TEST_CASE(test_in_out_unsigned_str_arg_val_get_value) {
		const in_out_raw_mem_descr<char> io_str   = in_out_str(s_val1,s_val2);
		const arg_val_ptr p_val(make_in_out_arg_val(name,(char *)io_str));
		arg_checker       al(tl);

		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}

	BOOST_AUTO_TEST_CASE(test_in_out_unsigned_str_arg_val_print) {
		const arg_val_ptr p_val(make_in_out_arg_val(name,(char *)s_val1));
		const std::string      expected = std::string("IN_OUT(")+(const char *)s_val1+","+out_arg_val::UNKNOWN+")";
		std::ostringstream        os;

		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	BOOST_AUTO_TEST_CASE(test_in_out_unsigned_str_arg_val_validate) {
		const arg_val_ptr p_val(make_in_out_arg_val(name,(char *)s_val1));
		arg_checker       al(tl);
		bool              status = true ;

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(status = p_val->validate(al,expected));
		BOOST_CHECK(!status);
	}

	BOOST_AUTO_TEST_CASE(test_in_out_unsigned_str_arg_val_update) {
		unsigned char     s_val3[sizeof(s_val2)];
		const arg_val_ptr p_val(make_in_out_arg_val(name,s_val3));
		arg_checker       al(tl);

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(p_val->update(al,expected));
		BOOST_CHECK_EQUAL((const char *)s_val2,(const char *)s_val3);
	}

	BOOST_AUTO_TEST_CASE(test_in_out_in_unsigned_str_arg_val_get_value) {
		const in_out_raw_mem_descr<char> io_str1 = in_str(s_val1);
		const arg_val_ptr p_val(make_in_out_arg_val(name,(char *)io_str1));
		arg_checker       al(tl);
		const arg_val_str expected((const char *)s_val1,IGNORE_STR);

		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}

	BOOST_AUTO_TEST_CASE(test_in_out_out_unsigned_str_arg_val_get_value) {
		const in_out_raw_mem_descr<char> io_str2 = out_str(s_val2);
		const arg_val_ptr p_val(make_in_out_arg_val(name,(char *)io_str2));
		arg_checker       al(tl);
		const arg_val_str expected(IGNORE_STR,(const char *)s_val2);

		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}
}
